program betweenrays;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  x1, x2, y1, y2, x3, y3, x4, y4: integer;
  d, d1, d2, xp1, yp1, xp2, yp2, a1, b1, c1, a2, b2, c2: real;
begin
  writeln('write the coordintes of two points on the 1st and 2nd rays');
  Readln (x1, y1, x2, y2, x3, y3, x4, y4);
  a1:=y1-y2;
  b1:=x2-x1;
  c1:=y2*x1-x2*y1;
  a2:=y3-y4;
  b2:=x4-x3;
  c2:=y4*x3-x4*y3;
  xp1:=((c2/b2)-(c1/b1))/((a1/b1)-(a2/b2));
  yp1:=-(a1/b1)*xp1-(c1/b1);
  if ((x1-x2)*(x1-xp1)>=0) and ((x3-x4)*(x3-xp1)>=0) then
    d:=0
  else
  begin
    d1:=(a1*x3+b1*y3+c1)/sqrt(a1*a1+b1*b1);
    d2:=(a2*x1+b2*y1+c2)/sqrt(a2*a2+b2*b2);
    xp1:=x3-a1*d1/sqrt(a1*a1+b1*b1);
    yp1:=y3-b1*d1/sqrt(a1*a1+b1*b1);
    xp2:=x1-a2*d2/sqrt(a2*a2+b2*b2);
    yp2:=y1-b2*d2/sqrt(a2*a2+b2*b2);
    if ((x1-x2)*(x1-xp1)>=0) then
      d:=d1 else
      d:=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    if ((x3-x4)*(x3-xp2)>=0) then
      d:=d2;
    if ((x1-x2)*(x1-xp1)>=0) and ((x3-x4)*(x3-xp2)>=0) then
      if (d1>d2) then
        d:=d1 else
        d:=d2;
  end;
  Writeln (d:0:3);
  readln;
end.
